import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Layout',
    redirect: '/search',
    component: () => import(/* webpackChunkName: "layout" */ '@/views/Layout'),
    children: [
      {
        path: 'search',
        name: 'Search',
        meta:{title:'项目申请工单'},
        component: () => import(/* webpackChunkName: "search" */ '@/views/Search'),
      },
      {
        path: 'work_order',
        name: 'WorkOrder',
        meta:{title:'工单审批'},
        component: () => import(/* webpackChunkName: "work_order" */ '@/views/WorkOrder'),
      },
      {
        path: 'project',
        name: 'Project',
        meta:{title:'项目信息'},
        component: () => import(/* webpackChunkName: "project" */ '@/views/Project'),
      },
      {
        path: 'goods',
        name: 'Goods',
        meta:{title:'项目商品信息'},
        component: () => import(/* webpackChunkName: "goods" */ '@/views/Goods'),
      }
    ]
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{
  if(from.path==='/goods'&&to.path==='/project'){
    next('/work_order')
  }
  else {
    next()
  }
})

export default router
